package com.kws.merchant.service.impl;


import com.kws.common.security.auth.AuthUtil;
import com.kws.merchant.domain.GoodsView;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kws.merchant.mapper.GoodsViewMapper;
import com.kws.merchant.service.GoodsViewService;
import com.kws.system.api.domain.SysUser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;

/**
 * 商品浏览记录表(GoodsView)表服务实现类
 *
 * @author yxy
 * @since 2024-11-04 09:11:24
 */
@Service("goodsViewService")
public class GoodsViewServiceImpl extends ServiceImpl<GoodsViewMapper, GoodsView> implements GoodsViewService {

    @Resource
    private GoodsViewMapper goodsViewMapper;


    /**
     * 分页查询列表
     */
    @Override
    public Page<GoodsView> pageList(GoodsView goodsView) {
        Page<GoodsView> page = new Page<>(0, 10);
        LambdaQueryWrapper<GoodsView> queryWrapper = Wrappers.lambdaQuery();

        return this.page(page, queryWrapper);
    }

    @Override
    public Long addGoodsView(Long merchantId,Long goodsId,int type) {
        SysUser sysUser = AuthUtil.getLoginUser().getSysUser();
        GoodsView goodsView = new GoodsView();
        goodsView.setType(type);
        goodsView.setUserId(sysUser.getUserId());
        goodsView.setMerchantId(merchantId);
        this.save(goodsView);
        return goodsView.getId();
    }





    /**
     * 根据类型时间查询访客数
     * @param companyId
     * @param time
     * @param type
     * @return
     */
    @Override
    public int merchantVisitorByTimeByType(Long companyId, String time, Integer type) {
        return goodsViewMapper.merchantVisitorByTimeByType(companyId,time,type);
    }

    /**
     * 总访客
     * @param userId
     * @return
     */
    @Override
    public Double countVisitor(Long userId) {
        return goodsViewMapper.countVisitor(userId);
    }

    /**
     * 总浏览量
     * @param userId
     * @return
     */
    @Override
    public Double countView(Long userId) {
        return goodsViewMapper.countView(userId);
    }

    /**
     * 根据年-月查询浏览时间
     * @param companyId
     * @return
     */
    @Override
    public Double countTimeByYearAndMonth(Long companyId,int year,int month,int type) {
        return goodsViewMapper.countTimeByYearAndMonth(companyId,year,month,type);
    }

    /**
     * 根据年-月查询浏览量人
     * @param companyId
     * @param year
     * @param month
     * @return
     */
    @Override
    public Double countPeopleByYearAndMonth(Long companyId, int year, int month,int type) {
        return goodsViewMapper.countPeopleByYearAndMonth(companyId,year,month,type);
    }

    /**
     * 根据年-月查询浏览量
     * @param companyId
     * @param type
     * @return
     */
    @Override
    public Double countViewTimeByYearAndMonth(Long companyId, Integer year, Integer month, Integer type) {
        return goodsViewMapper.countViewTimeByYearAndMonth(companyId,year,month,type);
    }

    /**
     * 按年月日查询小时浏览量
     * @param companyId
     * @param type
     * @param sql
     * @return
     */
    @Override
    public Double countViewBySql(Long companyId, Integer type, String sql) {
        return goodsViewMapper.countViewBySql(companyId,type,sql);
    }

    /**
     * 按年月日查询小时停留时间-浏览时间
     * @param companyId
     * @param type
     * @param sql
     * @return
     */
    @Override
    public Double countViewTimeBySql(Long companyId, Integer type, String sql) {
        return goodsViewMapper.countViewTimeBySql(companyId,type,sql);
    }

    /**
     * 根据sql查询访问量
     * @param companyId
     * @param type
     * @param sql
     * @return
     */
    @Override
    public Double countViewByPeopleSql(Long companyId, Integer type, String sql) {
        return goodsViewMapper.countViewByPeopleSql(companyId,type,sql);
    }

    /**
     * 查询访客数量
     * @param userId
     * @return
     */
    @Override
    public Double merchantVisitorByTime(Long userId,String time) {
        Double num=goodsViewMapper.merchantVisitor(userId,time);
        return num;
    }

    /**
     * 查询浏览量
     * @param userId
     * @param time
     * @return
     */
    @Override
    public Double merchantViewByTime(Long userId, String time) {
        Double num=goodsViewMapper.merchantViewByTime(userId,time);
        return num;
    }

}
